#!/bin/sh
varsfile="$1"; shift
dbgfile="$varsfile.dbg"

echo "The following requested variables were undefined:" > $dbgfile
echo >> $dbgfile

numnotfound="0"
for i in $@
do
    echo "searching in $varsfile for $i"
    numfound=`grep -c -w $i $varsfile`
    if [ "$numfound" = "0" ]
    then
        echo "not found!"
        numnotfound=`expr $numnotfound + 1`
        echo $i >> $dbgfile
    fi    
done

echo $numnotfound > "$varsfile"

if [ "$numnotfound" = "0" ] 
then
    echo "All the requested variables were defined." > $dbgfile
fi